package com.zrar.ak.gkpt.controller.record;

import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.record.IRecordInformationService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: RecordInformationController
 * @Description 备案信息Controller层
 * @Author liyang
 * @Time 2020/03/02
 */
@RestController
@RequestMapping("/recordInformation")
@Api(tags = "备案信息相关接口")
public class RecordInformationController {

    @Autowired
    private IRecordInformationService recordInformationService;
    @Autowired
    private IUserService userService;


    @RequestMapping(value = "recordAssign", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案信息下发", httpMethod = "POST", notes = "备案信息下发")
    public JsonResult recordAssign(HttpServletRequest request,
                                     @ApiParam(name = "formDataParameter", value = "备案信息下发相关参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        UserVO userVO = userService.getUserInformation(request);
        try {
            jsonResult = recordInformationService.recordAssign(jsonResult, formDataParameter, userVO);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }

    @RequestMapping(value = "recordCirculation", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案流转(回复,退回修改，结束)", httpMethod = "POST", notes = "备案信息流转(回复,退回修改，结束)")
    public JsonResult recordCirculation(HttpServletRequest request,
                                        @ApiParam(name = "formDataParameter", value = "备案流转相关参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        UserVO userVO = userService.getUserInformation(request);
        try {
            jsonResult = recordInformationService.recordCirculation(jsonResult, formDataParameter, userVO);
        } catch (Exception e) {
            e.printStackTrace();
            CommonTools.jsonResultSetParameter(jsonResult,JsonResultEnum.CODE_BUSINESS_EXCEPTION);
        }
        return jsonResult;
    }



    @RequestMapping(value = "recordInfoObtain", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案流转信息获取", httpMethod = "GET", notes = "备案流转信息获取")
    public JsonResult recordInfoObtain(HttpServletRequest request,
                                       @ApiParam(name = "buildUnitCode", value = "建设单位编码") @RequestParam String buildUnitCode){
        JsonResult jsonResult = new JsonResult();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.recordInfoObtain(jsonResult, buildUnitCode, userVO);
        return jsonResult;
    }


    @RequestMapping(value = "getRecordInfoList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取备案信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取备案信息列表-分页查询和条件查询")
    public JsonPageResult getRecordInformationList(HttpServletRequest request,
                                                    @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                                    @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                                    @ApiParam(name = "buildUnitName", value = "建设单位名称(模糊查询)") @RequestParam(value = "buildUnitName",required=false) String buildUnitName,
                                                    @ApiParam(name = "businessStatus", value = "备案状态(1.未回复 2.已回复 3.退回修改 4.已备案)") @RequestParam(value = "businessStatus",required=false) String businessStatus,
                                                    @ApiParam(name = "businessType", value = "备案类型(1.招投标 2.验收 3.验收 4.资金使用)") @RequestParam(value = "businessType",required=false) String businessType){
        JsonPageResult jsonResult = new JsonPageResult();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.getRecordInformationList(jsonResult, currentPage, pageSize, buildUnitName, businessStatus, businessType, userVO);
        return jsonResult;
    }









  /*  @RequestMapping(value = "saveContract", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案信息-合同备案录入", httpMethod = "POST", notes = "备案信息-合同备案录入")
    public JsonResult saveContract(HttpServletRequest request,
                                   @ApiParam(name = "formDataParameter", value = "备案信息-合同备案录入数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.saveContract(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "getContractList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取备案信息-合同备案", httpMethod = "GET", notes = "根据建设单位编码获取备案信息-合同备案")
    public JsonResult getContractListByBuildUnitCode(HttpServletRequest request,
                                                           @ApiParam(name = "buildUnitCode", value = "建设单位编码") @RequestParam String buildUnitCode){
        JsonResult jsonResult = new JsonResult();
        jsonResult = recordInformationService.getContractListByBuildUnitCode(jsonResult, buildUnitCode);
        return jsonResult;
    }









    @RequestMapping(value = "saveBid", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案信息-招投标备案录入", httpMethod = "POST", notes = "备案信息-招投标备案录入")
    public JsonResult saveBid(HttpServletRequest request,
                                   @ApiParam(name = "formDataParameter", value = "备案信息-招投标备案录入数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.saveBid(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "getBidList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取备案信息-招投标备案", httpMethod = "GET", notes = "根据建设单位编码获取备案信息-招投标备案")
    public JsonResult getBidListByBuildUnitCode(HttpServletRequest request,
                                                     @ApiParam(name = "buildUnitCode", value = "建设单位编码") @RequestParam String buildUnitCode){
        JsonResult jsonResult = new JsonResult();
        jsonResult = recordInformationService.getBidListByBuildUnitCode(jsonResult, buildUnitCode);
        return jsonResult;
    }


    @RequestMapping(value = "saveAccept", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案信息-验收备案录入", httpMethod = "POST", notes = "备案信息-验收备案录入")
    public JsonResult saveAccept(HttpServletRequest request,
                              @ApiParam(name = "formDataParameter", value = "备案信息-验收备案录入数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.saveAccept(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "getAcceptList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取备案信息-验收备案", httpMethod = "GET", notes = "根据建设单位编码获取备案信息-验收备案")
    public JsonResult getAcceptListByBuildUnitCode(HttpServletRequest request,
                                                @ApiParam(name = "buildUnitCode", value = "建设单位编码") @RequestParam String buildUnitCode){
        JsonResult jsonResult = new JsonResult();
        jsonResult = recordInformationService.getAcceptListByBuildUnitCode(jsonResult, buildUnitCode);
        return jsonResult;
    }



    @RequestMapping(value = "saveFunds", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "备案信息-资金使用备案录入", httpMethod = "POST", notes = "备案信息-资金使用备案录入")
    public JsonResult saveFunds(HttpServletRequest request,
                                 @ApiParam(name = "formDataParameter", value = "备案信息-资金使用备案录入数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = recordInformationService.saveFunds(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "getFundsList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取备案信息-资金使用备案", httpMethod = "GET", notes = "根据建设单位编码获取备案信息-资金使用备案")
    public JsonResult getFundsListByBuildUnitCode(HttpServletRequest request,
                                                   @ApiParam(name = "buildUnitCode", value = "建设单位编码") @RequestParam String buildUnitCode){
        JsonResult jsonResult = new JsonResult();
        jsonResult = recordInformationService.getFundsListByBuildUnitCode(jsonResult, buildUnitCode);
        return jsonResult;
    }*/
}
